package com.ybxx.base.action;

import java.util.Iterator;
import java.util.List;

import javax.annotation.Resource;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.ybxx.base.model.Ban;
import com.ybxx.base.service.UnitService;
import com.ybxx.core.web.action.BaseAction;
import com.ybxx.system.SystemConstants;
import com.ybxx.system.model.User;
import com.ybxx.base.model.Unit;

public class UnitAction extends BaseAction {
	@Resource
	private UnitService unitService;
	private String bid;
	private JSONArray arrayOne =new JSONArray();
	private String urlSign;
	private String checksign;
	private String ymonth;
	/**房间管理，查询单元资料*/
	public String queryTree(){
		/**获取当前登录者*/
		User user=(User)super.getSession().getAttribute(SystemConstants.SESSION_CURRENT_USER);
		List<Unit> units=unitService.queryTree(bid,user.getLoginid());
		
		for(Iterator<Unit> iter=units.iterator();iter.hasNext();){
			Unit unit=iter.next();
			JSONObject jsonObj=new JSONObject();
			jsonObj.put("id", "U"+unit.getUid());
			jsonObj.put("name",unit.getUname());
			jsonObj.put("pId","B"+bid);
			if(urlSign!=null && ("printcheck".equals(urlSign) || "fees".equals(urlSign))){
				jsonObj.put("isParent",false);
				jsonObj.put("nocheck",false);
				jsonObj.put("checked", checksign);
			}else{
				jsonObj.put("isParent",true);
				jsonObj.put("nocheck",true);
			}
			if(urlSign==null || "".equals(urlSign)){
				jsonObj.put("url","../base/queryPage_RoomInfo.action?uid="+unit.getUid()+"&urlSign="+urlSign);
				jsonObj.put("target","_self");
			}else if("residents".equals(urlSign)){
				jsonObj.put("url","../base/queryPage_Residents.action?uid="+unit.getUid()+"&urlSign="+urlSign);
				jsonObj.put("target","_self");
			}else if("anmeterManager".equals(urlSign)){
				jsonObj.put("url","../dashboard/init_Anmeter.action?uid="+unit.getUid()+"&urlSign="+urlSign);
				jsonObj.put("target","_self");
			}else if("watermeterManager".equals(urlSign)){
				jsonObj.put("url","../dashboard/init_Watermeter.action?uid="+unit.getUid()+"&urlSign="+urlSign);
				jsonObj.put("target","_self");
			}else if("anmeterread".equals(urlSign)){
				jsonObj.put("url","");//"../dashboard/queryReadForm_Anmeter.action?unitid=U"+unit.getUid()+"&urlSign="+urlSign+"&ymonth="+ymonth);
				jsonObj.put("target","_self");
				jsonObj.put("click","showAnmeterRead('U"+unit.getUid()+"','"+urlSign+"');");
			}else if("fees".equals(urlSign)){
				jsonObj.put("url","");//"../dashboard/queryReadForm_Anmeter.action?unitid=R"+room.getRid()+"&urlSign="+urlSign+"&ymonth="+ymonth);
				jsonObj.put("target","_self");
				jsonObj.put("click","showFees('U"+unit.getUid()+"','"+urlSign+"');");
				jsonObj.put("isParent",true);
			}
			
			arrayOne.add(jsonObj);
		}
		return "queryTree";
	}
	public String getBid() {
		return bid;
	}
	public void setBid(String bid) {
		this.bid = bid;
	}
	public JSONArray getArrayOne() {
		return arrayOne;
	}
	public void setArrayOne(JSONArray arrayOne) {
		this.arrayOne = arrayOne;
	}
	public String getUrlSign() {
		return urlSign;
	}
	public void setUrlSign(String urlSign) {
		this.urlSign = urlSign;
	}
	public String getChecksign() {
		return checksign;
	}
	public void setChecksign(String checksign) {
		this.checksign = checksign;
	}
	public String getYmonth() {
		return ymonth;
	}
	public void setYmonth(String ymonth) {
		this.ymonth = ymonth;
	}
	
}
